package org.zuoye.action;

import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class FileDownload extends ActionSupport{
	private String fileUrl;
	private String fileName;
	
    public String getFileName() {  
        try {  
            return new String(fileName.getBytes(),"ISO8859-1");  
        } catch (UnsupportedEncodingException e) {  
            return this.fileName;
        } 
	}
	public void setFileName(String fileName) {
		this.fileName = fileName;
	}
	public String getFileUrl() {
		return fileUrl;
	}
	public void setFileUrl(String fileUrl) {
		this.fileUrl = fileUrl;
	}
	
	public InputStream getDownloadFile() throws Exception  
    {
		/*在此处给文件名赋值会使注解赋值中文名时无法获取正确的名字，所以直接在execute方法中先给文件名赋值即可*/
//		this.fileName=getFileUrl().trim().substring(getFileUrl().lastIndexOf("\\")+1);
//		System.out.println(fileName);
//		this.fileName = new String(this.fileName.getBytes("ISO-8859-1"),"UTF-8");
//		System.out.println("转码后"+fileName);
//		获取资源路径  
        return ServletActionContext.getServletContext().getResourceAsStream("upload/"+fileName);           
    }
	public String execute() throws Exception {  
		this.fileName=getFileUrl().trim().substring(getFileUrl().lastIndexOf("\\")+1);
		System.out.println("点击了下载的文件名为："+fileName);
        return SUCCESS;  
    }

}
